package magicloan.auctionpocket.ui.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextSwitcher;
import com.chad.library.adapter.base.BaseQuickAdapter;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import magicloan.auctionpocket.R;
import magicloan.auctionpocket.adapter.SecondFragmentReAdapter;
import magicloan.auctionpocket.bean.ProduceBean;
import magicloan.auctionpocket.ui.base.BaseFragment;
import magicloan.auctionpocket.view.VerticalTextViewHelper;

/**
 * Created by hechao on 2018/1/25.
 */
public class SecondFragment extends BaseFragment {

    private TextSwitcher mTextSwitcher ;
    private ArrayList mVerticalList ;
    private VerticalTextViewHelper mVerticalTvHelper ;
    private SecondFragmentReAdapter mAdapter ;
    private ArrayList<ProduceBean> mReDateList ;

    @Override
    protected int setFgContentView() {
        return R.layout.fg_second;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void beforeInitView() {

        mVerticalList = new ArrayList() ;
        mVerticalList.add("哈哈哈哈哈哈 你好啊 ");
        mVerticalList.add("1234567891 你好啊 ");
        mVerticalList.add("oooooooooo 你好啊 ");

        mReDateList = new ArrayList<>() ;
        for ( int i = 0 ; i < 10 ; i ++ ){
            ProduceBean instance = new ProduceBean();
            mReDateList.add(instance);
        }

        initAdapter();

    }

    @Override
    protected void afterInitView() {

        mTextSwitcher = (TextSwitcher) mContentView.findViewById(R.id.textSwitcher1);
        mVerticalTvHelper = new VerticalTextViewHelper(mActivity);
        //垂直滚动LV
        if ( mVerticalList!=null && mVerticalList.size()>0 ){
            mVerticalTvHelper.setData(mVerticalList);
            mVerticalTvHelper.initSwitcher(mTextSwitcher, new VerticalTextViewHelper.OnSwitchTvClickListener() {
                @Override
                public void onClick(int position) {

                }
            });
        }

        RecyclerView recylerV = (RecyclerView) mContentView.findViewById(R.id.recylerv);
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        recylerV.setLayoutManager(layoutManager);
        recylerV.setAdapter(mAdapter);
        mAdapter.addData(mReDateList);
        mAdapter.notifyDataSetChanged();

        mViewEmpty = mContentView.findViewById(R.id.view_empty);
        mViewEmpty.setVisibility(View.INVISIBLE);

    }

    private void initAdapter() {

        mAdapter = new SecondFragmentReAdapter(R.layout.fg_second_re_item, mActivity);
        mAdapter.setOnLoadMoreListener(new MyRequestLoadMoreListener());
        mAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);

    }

    private class MyRequestLoadMoreListener implements BaseQuickAdapter.RequestLoadMoreListener {

        @Override
        public void onLoadMoreRequested() {
//            if (!isLoadMore) {
//                isLoadMore = true;
//                currentPage = ++currentPage;
//                mService.getRefreshLoanData(NetConstance.GetLoanData, currentPage, 6);
//            }
        }

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void afterConnectSuccess(String flag, JSONObject request) throws JSONException {

    }

    @Override
    public void afterConnectFail(String flag, JSONObject result, String cache) throws JSONException {

    }

}
